package com.wy.xinzhi.common.services;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.orm.hibernate4.support.HibernateDaoSupport;

import com.wy.component.properties.PropertiesUtil;
import com.wy.framework.dao.IDataBaseDao;
import com.wy.framework.services.AbstractBaseService;
import com.wy.framework.services.login.LoginService;
import com.wy.xinzhi.common.pojos.TBodyRecord;
import com.wy.xinzhi.common.pojos.TFoodRecord;

public class BodyRecordService extends AbstractBaseService {
	private static Logger logger = LoggerFactory.getLogger(LoginService.class);
	static PropertiesUtil p = new PropertiesUtil();
	
	Date d = new Date(System.currentTimeMillis()); // 年月日

	Date now = new Date();
	SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");// 可以方便地修改日期格式
	String dqsj = dateFormat.format(now);

	private JdbcTemplate jdbcTemplate;
	private HibernateDaoSupport hibernateDao;
	private IDataBaseDao dataBaseDao;
	
	public List<Map<String,Object>> queryBodyRecord(String customerId) {
		StringBuffer sql = new StringBuffer("SELECT  T.*,DATE_FORMAT(T.`create_date`,'%Y-%m-%d') AS sday FROM `t_body_record` T where customer_id=  "+customerId);
		List<Map<String, Object>> resultList = new ArrayList();
		resultList = dataBaseDao.getJdbcTemplate().queryForList(sql.toString());
		logger.debug("查询客户"+customerId+"的身体信息列表，详细："+sql.toString());
		return resultList;
	}
	
	public void saveBodyRec(TBodyRecord bodyRecord) {
		hibernateDao.getHibernateTemplate().saveOrUpdate(bodyRecord);
	}
	
	public TBodyRecord getBodyRecordById(String reId)
	{
		TBodyRecord record = null;
		List list = hibernateDao.getHibernateTemplate().find(" FROM TBodyRecord T WHERE T.reId = ?", reId);
		if(list.size()>0)
		{
			record=(TBodyRecord) list.get(0);
			return record;
		}
		return null;
	}
	
	public void deleteBodyRecById(String reId)
	{
		TBodyRecord record = new TBodyRecord();
		record.setReId(reId);
		hibernateDao.getHibernateTemplate().delete(record);
	}
	
	public JdbcTemplate getJdbcTemplate() {
		return jdbcTemplate;
	}
	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}
	public HibernateDaoSupport getHibernateDao() {
		return hibernateDao;
	}
	public void setHibernateDao(HibernateDaoSupport hibernateDao) {
		this.hibernateDao = hibernateDao;
	}
	public IDataBaseDao getDataBaseDao() {
		return dataBaseDao;
	}
	public void setDataBaseDao(IDataBaseDao dataBaseDao) {
		this.dataBaseDao = dataBaseDao;
	}
}
